package org.i77soft.games.MineAcerLite;

import org.loon.framework.android.game.core.EmulatorButtons;
import org.loon.framework.android.game.core.EmulatorListener;
import org.loon.framework.android.game.core.graphics.Screen;
import org.loon.framework.android.game.core.graphics.Screen.LKey;
import org.loon.framework.android.game.core.graphics.device.LGraphics;
import org.loon.framework.android.game.core.timer.LTimerContext;

import android.view.KeyEvent;

import org.i77soft.games.LGame.engine.Scene;
import org.i77soft.games.LGame.engine.Controller;
import org.i77soft.games.MineAcerLite.scenes.IntroScene;

public class MineSweeper extends Screen /*implements EmulatorListener*/ {

    public final Controller controller;
    private Scene screen;

    public MineSweeper() {
        controller = new Controller();
    }

    public void onLoaded() {
        /*
        EmulatorButtons ebs = getEmulatorButtons();
        if (ebs != null) {
            ebs.hideRight();
        }
        //*/
        setScene(new IntroScene());
    }

    public void setScene(Scene screen) {
        this.screen = screen;
        screen.init(this);
    }

    public void tick() {
        if (screen != null) {
            controller.tick();
            screen.tick();
        }
    }

    public void render(LGraphics g) {
        if (screen != null) {
            screen.render(g);
        }
    }

    public void alter(LTimerContext context) {
        tick();
    }

    @Override
    public synchronized void draw(LGraphics g) {
        render(g);
    }

    @Override
    public void onTouchDown(LTouch e) {
        if (screen != null) {
            screen.clicked = true;
        }
    }

    @Override
    public void onTouchUp(LTouch e) {

    }

    @Override
    public void onTouchMove(LTouch e) {

    }

    /*
    @Override
    public void onUpClick() {
        controller.keyPressed(KeyEvent.KEYCODE_DPAD_UP);
    }

    @Override
    public void onLeftClick() {
        controller.keyPressed(KeyEvent.KEYCODE_DPAD_LEFT);
    }

    @Override
    public void onRightClick() {
        controller.keyPressed(KeyEvent.KEYCODE_DPAD_RIGHT);
    }

    @Override
    public void onDownClick() {
        controller.keyPressed(KeyEvent.KEYCODE_DPAD_DOWN);
    }

    @Override
    public void onTriangleClick() {

    }

    @Override
    public void onSquareClick() {

    }

    @Override
    public void onCircleClick() {

    }

    @Override
    public void onCancelClick() {

    }

    @Override
    public void unUpClick() {
        controller.keyReleased(KeyEvent.KEYCODE_DPAD_UP);
    }

    @Override
    public void unLeftClick() {
        controller.keyReleased(KeyEvent.KEYCODE_DPAD_LEFT);
    }

    @Override
    public void unRightClick() {
        controller.keyReleased(KeyEvent.KEYCODE_DPAD_RIGHT);
    }

    @Override
    public void unDownClick() {
        controller.keyReleased(KeyEvent.KEYCODE_DPAD_DOWN);
    }

    @Override
    public void unTriangleClick() {

    }

    @Override
    public void unSquareClick() {

    }

    @Override
    public void unCircleClick() {

    }

    @Override
    public void unCancelClick() {

    }
    //*/

    @Override
    public void onKeyDown(LKey e) {
        controller.keyPressed(e.getKeyCode());
    }

    @Override
    public void onKeyUp(LKey e) {
        controller.keyReleased(e.getKeyCode());
    }

}
